package com.celesea.workflow.demo.service;

import com.celesea.framework.entity.BusEntity;
import com.celesea.framework.service.AbstractBaseService;
import com.celesea.framework.util.EnvUtil;
import com.celesea.workflow.demo.dao.DemoPermDao;
import com.celesea.workflow.demo.entity.DemoPerm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Creator yuanhaitao
 */
@Service
public class DemoPermServiceImpl extends AbstractBaseService<DemoPerm> implements DemoPermService {

    @Autowired
    private DemoPermDao demoPermDao;

    @Override
    public List<DemoPerm> findByDemo(String demoId) {
        return demoPermDao.selectByExample(buildExample(demoId));
    }

    @Override
    public int deleteByDemo(String demoId) {
        return demoPermDao.deleteByExample(buildExample(demoId));
    }

    private Example buildExample(String demoId) {
        Example example = new Example(DemoPerm.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo(BusEntity.TALENT_ID, EnvUtil.getTenantId())
                .andEqualTo("demoId", demoId);
        return example;
    }
}
